<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>查看用户</title>
</head>
<body>
<jsp:include page="/incloud/header.jsp" />

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp" />
    <!-- Sidebar Navigation end-->
    <div class="page-content">

        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">用户列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <div class="title">
                <form class="form-inline" method="get" action="/user/findPage">
                    <input type="hidden" name="currPage" value="1">
                    <div class="form-group">
                        <label for="inlineFormInput" class="sr-only">Name</label>
                        <input id="inlineFormInput" type="text" name="realName"  value="${realName}" placeholder="按名字查找" class="mr-sm-3 form-control">
                    </div>
                    <div class="form-group">
                        <input type="submit" value="查询" class="btn btn-primary">
                    </div>
                </form>

            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>用户名</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>简介</th>
                        <th>操作</th>
                        <th>加关注</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="user" items="${pageData.data}">

                        <tr>
                            <th scope="row">${user.id}</th>
                            <th>${user.username}</th>
                            <td>${user.realName}</td>
                            <td>${user.gender==1?'男':'女'}</td>
                            <td>${user.age}</td>
                            <td>${user.info}</td>
                            <td>
                                <input type="submit" value="详细信息" class="btn-xs btn-primary userDetail" onclick="userDetail(${user.id},${user.isSecret})">
                            </td>
                            <td>
                                <input type="checkbox" value="" class="checkbox-template"  onclick="addFocus(${user.id},event)"
                                    ${userFocusIdList.contains(user.id)?'checked':''}>
                            </td>
                        </tr>
                    </c:forEach>


                    </tbody>
                </table>
            
                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="#" aria-label="Previous" onclick="pre()">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>

                        <c:forEach begin="1" end="${pageData.totalPage}" varStatus="row">

                            <li><a ${row.count==pageData.currPage? 'style="background-color: cornflowerblue"' : ''}
                                    href="/user/findPage?currPage=${row.count}&realName=${realName}">${row.count}</a></li>

                        </c:forEach>


                        <li>
                            <a href="#" aria-label="Next" onclick="next()">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <jsp:include page="/incloud/footer.jsp" />
    </div>
</div>

<!-- JavaScript files-->


<script type="text/javascript">

    /**
     * 添加/取消关注
     * @param userId
     */
    function addFocus(userId,event){
        if("${loginUser.id}"==userId){
            layer.msg("不能关注自己啊！");
            event.preventDefault();
            return;
        }

        $.post("/user/addFocus",{"userId":userId},function (flag){
            if(flag=='1'){
                layer.msg("加关注成功！")
            }else {
                layer.msg("取消关注成功！")
            }
        })
    }




    /**
     * 用户详细
     * @param userId
     */
    function userDetail(userId,isSecret){
        if(isSecret=='0'){
            layer.msg("对方设置了私密！")
            return;
        }

        location.href="/user/userDetail?userId="+userId+"&flag=detail"
    }


    /**
     * 上一页
     */
    function pre(){
        if(${pageData.currPage-1==0}){
            layer.msg("已经到顶了！")
            return;
        }

        location.href="/user/findPage?currPage=${pageData.currPage-1}&realName=${realName}"
    }

    /**
     * 下一页
     */

    function next(){
        if(${pageData.currPage+1>pageData.totalPage}){
            layer.msg("已经到底了！")
            return;
        }

        location.href="/user/findPage?currPage=${pageData.currPage+1}&realName=${realName}"
    }





    $(function(){
		
		//用户列表，查看详情，通过class名字userDetail来找
		$("#userDetail").click(function () {
		    console.log("你点击了用户详情");
		    window.location.href = '/html/user_detail.jsp'
		});

		
	})
	
</script>
</body>
</html>